package com.yunxi.controller.basedata;

import com.yunxi.basedata.pojo.FactoryVO;
import com.yunxi.basedata.service.FactoryDubboService;
import com.yunxi.core.web.ApiResult;
import com.yunxi.core.web.CurrentUser;
import com.yunxi.core.web.LoginInfo;
import com.yunxi.core.web.ResponseUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import java.util.List;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 工厂信息 前端控制器
 * </p>
 *
 * @author
 * @since 2019-05-29
 */
@RestController
@RequestMapping("/admin/factory")
@Api(tags = "pms:factory", description = "工厂信息接口")
public class FactoryController {

    private static final Logger logger = LoggerFactory.getLogger(FactoryController.class);

    @Autowired
    FactoryDubboService factoryDubboService;

    @GetMapping("/page")
    @ApiOperation(value = "查询分页")
    public ApiResult page(FactoryVO factoryVO, Integer pageNum, Integer pageSize) throws Exception {
        return ResponseUtil.ok(factoryDubboService.findPageByVO(factoryVO, pageNum, pageSize));
    }

    @GetMapping("/list")
    @ApiOperation(value = "不分页查询")
    public ApiResult page(FactoryVO factoryVO) {
        return ResponseUtil.ok(factoryDubboService.findListByVo(factoryVO));
    }

    @GetMapping("/load")
    @ApiOperation(value = "读取单个")
    public ApiResult load(String id, @CurrentUser LoginInfo loginInfo) throws Exception {
        return ResponseUtil.ok(factoryDubboService.getById(id));
    }

    @PostMapping("/save")
    @ApiOperation(value = "保存信息")
    public ApiResult save(@RequestBody FactoryVO factoryVO, @CurrentUser LoginInfo loginInfo) throws Exception {
        factoryDubboService.saveOrUpdate(factoryVO);
        return ResponseUtil.ok("success");
    }

    @PostMapping("/del")
    @ApiOperation(value = "删除")
    public ApiResult del(@RequestBody List<FactoryVO> factoryVOList) throws Exception {
        factoryDubboService.removeByListVo(factoryVOList);
        return ResponseUtil.ok("success");
    }

/*@PostMapping("/export")
@ApiOperation(value = "导出excel")
public Object export(@RequestParam Map<String,Object> params) throws Exception {
return ResponseUtil.ok(factoryDubboService.findMapByList(params));
}*/
}
